//
//  DocumentLoadOperation.m
//  MediaInfoGUI
//
//  Created by Olivier Larivain on 2/27/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "DocumentLoadOperation.h"
#import "MediaInfoController.h"

@implementation DocumentLoadOperation
@synthesize appController;
@synthesize mediaInfoController;
@synthesize filenames;
@synthesize detailLevel;

- (id) initWithFields: (AppController*) applicationController miController: (MediaInfoController*) miController filenames: (NSArray*) files detailLevel: (DetailLevel) detail;
{
  self = [super init];
  if(!self)
  {
    return nil;
  }
  
  [self setAppController: applicationController];
  [self setMediaInfoController: miController];
  [self setFilenames: files];
  [self setDetailLevel: detail];
  return self;
}
-(void) main
{
  BOOL keepPrevious = FALSE;
  for(NSString *filename in filenames)
  {
    [mediaInfoController loadDocument: filename detailLevel:detailLevel keepPrevious: keepPrevious];    
    keepPrevious = TRUE;
    if([self isCancelled])
    {
      return;
    }
  }
    //[mediaInfoController loadDocuments:URLs detailLevel:detailLevel];

  if(![self isCancelled])
  {
    [appController performSelectorOnMainThread:@selector(loadFinished) withObject:nil waitUntilDone:TRUE];    
  }
}
@end
